
package net.vinote.smart.platform.service.action;

import java.sql.SQLException;

import net.vinote.smart.platform.comm.PlatformConst;
import net.vinote.smart.platform.module.database.DBManager;
import net.vinote.smart.platform.module.database.DBManagerFactory;
import net.vinote.smart.platform.module.database.DBTransaction;
import net.vinote.smart.platform.module.database.bo.BizObject;
import net.vinote.smart.platform.service.util.AutoInjection;
import net.vinote.smart.platform.service.util.Permission;
import net.vinote.smart.platform.service.util.Permission.PermissionEnum;


/**
 * 角色对象关系表Action类
 * 
 * @author 郑俊伟
 */
public class RoleObjectRelaAction
{

	/**
	 * 角色ID编号,以逗号分割
	 */
	@AutoInjection
	private String roles;

	@AutoInjection
	private String objectID;

	@AutoInjection
	private String objectType;

	/**
	 * 设置关联对象有效角色
	 * 
	 * @return
	 * @throws SQLException
	 */
	@Permission({ PermissionEnum.SMART_ROLE_RELATION_UPDATE })
	public String setRoleObjectRela(DBTransaction tx) throws SQLException
	{
		// 清理原有配置
		DBManager bm = DBManagerFactory.getInstance("role_object_rela");
		tx.join(bm);
		bm.deleteWhereSql("objectID=? and objectType=?", objectID, objectType);
		// 重新设置角色关联关系
		if (roles != null && !"".equals(roles))
		{
			for (String roleID : roles.split(PlatformConst.SPLIT_COMMA))
			{
				BizObject bo = new BizObject();
				bo.setAttribute("roleID", roleID);
				bo.setAttribute("objectID", objectID);
				bo.setAttribute("objectType", objectType);
				bm.saveBizObject(bo);
			}
		}
		return PlatformConst.SUCCESS;
	}
}
